﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 版权所有 (c) 2022 北京超维景生物科技有限公司 保留所有权利。
 * 
 * 创建者：huangyang
 * 电子邮箱：huangyang@tvscope.cn
 * 创建时间：2023/2/22 17:59:23
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImageK.Gui
{
    public class GUI
    {
        private static Color scrollbarBackground = Color.FromArgb(245, 245, 245);

        /**
         * Get maximum bounds for the screen that contains a given component.
         * @param component An AWT component located on the desired screen.
         * If <code>null</code> is provided, the default screen is used.
         * @param accountForInsets Deduct the space taken up by menu and status bars, etc.
         * @return Rectangle of bounds.
         */
        public static Rectangle getScreenBounds(Control component, bool accountForInsets)
        {
            return new Rectangle(0, 0, 0, 0);
            //todo:

            // if (GraphicsEnvironment.isHeadless())
            //     return new Rectangle(0, 0, 0, 0);
            // GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            // GraphicsConfiguration gc = component == null ? ge.getDefaultScreenDevice().getDefaultConfiguration() :
            //     component.getGraphicsConfiguration();
            // Insets insets = accountForInsets ? Toolkit.getDefaultToolkit().getScreenInsets(gc) : null;
            // return shrinkByInsets(gc.getBounds(), insets);
        }

		public static Rectangle getScreenBounds(Control component)
        {
            return getScreenBounds(component, false);
        }

        public static Rectangle getScreenBounds()
        {
            return getScreenBounds((Control)null);
        }

        /** Returns a new NonBlockingGenericDialog with the given title
         * if Prefs.nonBlockingFilterDialogs is 'true' and 'imp' is
         * displayed, otherwise returns a GenericDialog.
         * @param title Dialog title
         * @param imp The image associated with this dialog
        */
        public static GenericDialog newNonBlockingDialog(String title, ImagePlus imp)
        {
            if (Prefs.nonBlockingFilterDialogs && imp != null && imp.getWindow() != null)
            {
                NonBlockingGenericDialog gd = new NonBlockingGenericDialog(title);
                gd.imp = imp;
                return gd;
            }
            else
                return new GenericDialog(title);
        }

        /**
         * Scales an AWT component according to {@link Prefs#getGuiScale()}.
         * @param component the AWT component to be scaled. If a container, scaling is applied to all its child components
         */
        public static void scale(Control component)
        {
            //todo:
            // float scale = (float)Prefs.getGuiScale();
            // if (scale==1f)
            //     return;
            // if (component is Container)
            //     scaleComponents((Container)component, scale);
            // else
            //     scaleComponent(component, scale);
        }

        /** Works around an OpenJDK bug on Windows that
         * causes the scrollbar thumb color and background
         * color to be almost identical.
        */
        public static void fixScrollbar(TrackBar sb)
        {
            if (IJ.IsWindows())
                sb.BackColor = scrollbarBackground;
        }
    }
}
